package com.hyf.zookeeper.core;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.io.IOException;

public class ZKExists {

    private static ZooKeeper zk;

    private static ZookeeperConnection zkConn;

    public static Stat znode_exists(String path) throws KeeperException, InterruptedException {
        return zk.exists(path,true);
    }

    public static void main(String[] args){
        String path="/MyFirstZnode2";

        zkConn=new ZookeeperConnection();
        try {
            zk=zkConn.connect("47.93.157.178:12181");
            Stat stat = znode_exists(path);
            if(stat!=null){
                System.out.println("Node  exists and the node version is:"+stat.getVersion());
            }else{
                System.out.println("Node does not exists");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (KeeperException e) {
            e.printStackTrace();
        }
    }
}
